// 原材料出库查询 -- wzhg
import React, { Component } from 'react'
import {fetchData} from '../../../components/AjaxConsumer'
import {ListBox} from '../../../components'
import { Modal } from 'antd';

export default class ListProSellOutSnPage extends Component{
    constructor(props) {
        super(props);
        //行操作列表-已弃用
        this.rowOperation = [
            
        ];
        //header 操作列表111
        this.headerOperation = [
            {
                handleName: 'export',
                showName: 'Excel',
                iconClass: 'file-excel'
            }
        ];

        //table列表展示列配置
        //showName、columnName 必有属性， columnWidth 可选，默认100, columnHidden: true 列隐藏
        // foreverHidden永久隐藏
        this.tableColumn = {
            storageKey: 'id',
            data: [
                {
                    showName: 'id',
                    columnName: 'sellOutId',
                    columnHidden:true,
                    foreverHidden: true
                },
                {
                    showName: '销售出库单号',
                    columnName: 'sellOutNo',
                    columnWidth: 110
                },
                // {
                //     showName: '采购订单号',
                //     columnName: 'purchaseNo'
                // },
                {
                    showName: '合同编号',
                    columnName: 'contractNo',
                    columnWidth: 120
                },
                {
                    showName: '条码',
                    columnName: 'barcode',
                    columnWidth: 150
                },
                {
                    showName: '型号',
                    columnName: 'model'
                },
                {
                    showName: '型号类型',
                    columnName: 'modelType'
                },
                {
                    showName: '单位',
                    columnName: 'unit',
                    columnWidth: 80
                },
                {
                    showName: '数量',
                    columnName: 'amount',
                    columnWidth: 80
                },
                {
                    showName: '库位',
                    columnName: 'wlCode',
                    columnWidth: 80
                },
                {
                    showName: '扫描时间',
                    columnName: 'gmtCreate',
                    columnWidth: 135
                }
            ]
        };

        //搜索属性配置，如果字段不配置，默认是input搜索
        // 搜索类型：
        //      1、输入框 type='input'， 默认
        //      2、时间 type='date'
        //      3、数字 type='number'
        //      4、下拉框 type='select'
        this.searchComponentData = [
            {
                showName: '型号类型',
                name: 'modelType',
                type: 'select',
                optionList: [//下拉框的信息
                ]
            },
            {
                showName: '数量',
                name:'amount',
                type: 'number',
                maxName:'amountMax', //最大值
                minName:'amountMin'  //最小值
            },
            {
                showName:'创建日期',
                name:'gmtCreate',
                type: 'date',
                maxName:'gmtCreateMax',
                minName:'gmtCreateMin'
            }
        ];

    }

    // 行操作
    rowHandles = (strHandles, rowObj) => {
        if (strHandles == 'export') {
            this.exportXlsHandle(rowObj);
        }
    }

    exportXlsHandle = (conditonData) => {
        console.log('-------导出条件--------', conditonData);
        let param = '?'
        for (let key in conditonData) {
            if (conditonData[key] != '') {
                console.log(key, conditonData[key]);
                param = param + key + '=' + conditonData[key] + '&'
            }
        }
        console.log(param);
        window.location.href = '/product/proselloutsn/listSnExp' + param;
    }

    componentWillMount() {
        const dicType = 'model_type_p';
        const options= {
            url: '/base/dic/get/' + dicType,
            type: 'get',
            condition:{}
        };
        //先写死，后面再改
        fetchData(this, options, this.dicInitCallBackHandle);
    }

    //下拉框 初始化
    dicInitCallBackHandle = (resData)=>{
        //alert('resData' + JSON.stringify(resData, null, 4));
        let optionList = [];
        let tmp = {};
        tmp.optionKey = '';
        tmp.optionShow = '';
        optionList.push(tmp);
        resData.data.map( (e,index) => {
            let tmp = {};
            tmp.optionKey = e.dicCode;
            tmp.optionShow = e.dicName;
            optionList.push(tmp);
        });

        //alert('optionList' + JSON.stringify(optionList, null, 4));
        this.tableColumn.data[5].showOption = optionList;
        this.searchComponentData[0].optionList = optionList;
    }

    //刷新列表
    refreshHandle = () => {
        this.refs.proSellOutSnList.refreshHandle();
    }

    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;

        return(
            <div>
                <ListBox
                    ref = 'proSellOutSnList'
                    title="销售出库明细查询"
                    isHideLeft={isHideLeft}
                    tableColumnData = {this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url = '/product/proselloutsn/list'
                    rowHandles = {this.rowHandles}
                    rowOperation = {this.rowOperation}
                    headerOperation = {this.headerOperation}
                    isRowSingle = "true"
                />
            </div>
        )
        
    }

}